//enigma  social tooltip js
jQuery(function() {
    jQuery('li').tooltip();
    jQuery("[data-toggle='tooltip']").tooltip();
    jQuery("[data-toggle='popover']").popover();
});
var baseURL = '';
var Dosweb = function() {
    var expandEmail = function() {
        jQuery("#expandEmail").click(function() {
            jQuery('.sliderOuter').animate({left: "0px"}, 400);
        });
    };
    
    var autoExpand = function() {
        jQuery('.sliderOuter').animate({left: "0px"}, 400);
    };
    
    var collapseEmail = function() {
        jQuery("#collapseEmail").click(function() {
            jQuery('.sliderOuter').animate({left: "-1000px"}, 400);
        });
    };

    var joinOurEmail = function() {
        jQuery("#join_now").click(function(event) {
            var str = jQuery("#joinOurEmail").serialize();
            var firstName = jQuery('#first_name').val();
            var lastName = jQuery('#last_name').val();
            var email = jQuery('#email').val();
            if(firstName == '' || lastName == '' || email == '') {
                jQuery('#errorMsg').html("First Name, Last Name, Email are required.");
                event.preventDefault();
                return;
            }
            if(firstName.length > 20) {
                jQuery('#errorMsg').html("First Name no more than 20 characters.");
                event.preventDefault();
                return;
            }
            if(lastName.length > 20) {
                jQuery('#errorMsg').html("LastName no more than 20 characters.");
                event.preventDefault();
                return;
            }
            if(email.length > 50) {
                jQuery('#errorMsg').html("Email no more than 20 characters.");
                event.preventDefault();
                return;
            }
            if(__validateEmail(email) == false) {
                jQuery('#errorMsg').html("Please enter a valid email address.");
                event.preventDefault();
                return;
            }
            __resetForm();
            __submitData(str);
        });
    };

    var __submitData = function(formData){
        var joinOurEmailList = jQuery.ajax({
            type: "POST",
            url: baseURL + "email_sign_up.php",
            data: formData
        });
        jQuery('#joinOurEmail').hide();
        joinOurEmailList.done(function(response) {
            if (response.success == false) {
                __showError(response.message);
            } else {
                __showSuccess(response.message);
            }
        });
        joinOurEmailList.fail(function(jqXHR, textStatus) {
            __showError(textStatus);
        });
    }

    var __showError = function(message) {
        jQuery('#errorMsg').css("display","block");
        jQuery('#errorMsg').html(message);
    };

    var __showSuccess = function(message) {
        jQuery('#successMsg').css("display","block");
        jQuery('#successMsg').html(message);
    }

    var __resetForm = function() {
        jQuery('#errorMsg').css("display","none");
        jQuery('#successMsg').css("display","none");
    }

    var __validateEmail = function(email) {
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    };

    return {
        //main function to initiate the module
        init: function() {
            expandEmail();
            collapseEmail();
            joinOurEmail();
        },
        autoExpand: function() {
            return autoExpand();
        }
    };
}();

/*----------------------------------------------------*/
/*	Scroll To Top Section
 /*----------------------------------------------------*/
jQuery(document).ready(function() {
    baseURL = jQuery('#base_url').val();
    Dosweb.init();

    //jQuery('#expandEmail').trigger('click');
    jQuery(window).scroll(function() {
        if (jQuery(this).scrollTop() > 100) {
            jQuery('.enigma_scrollup').fadeIn();
        } else {
            jQuery('.enigma_scrollup').fadeOut();
        }
    });

    jQuery('.enigma_scrollup').click(function() {
        jQuery("html, body").animate({
            scrollTop: 0
        }, 600);
        return false;
    });

});


jQuery.browser = {};
(function() {
    jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
})();
